package cmdb

import (
	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/net/ghttp"
	"github.com/gogf/gf/util/gconv"
	"minefieldplatform-go/app/service/cmdb"
)

func GpuDiscover(r *ghttp.Request) {
	var data = g.Map{
		"ip":           r.Get("ip"),
		"cpu_cores":    r.Get("cpu"),
		"total_memory": r.Get("memory"),
		"gpu_numbers":  r.Get("gpu"),
		"mount_with":   r.Get("mount"),
		"area":         r.Get("area"),
		"node_status":  r.Get("proc"),
	}

	if data["node_status"] == "1" {
		data["node_status"] = "运行中"
	} else {
		data["node_status"] = "已停止"
	}

	data["total_memory"] = gconv.Float32(data["total_memory"]) / 1000

	count := cmdb.GpuDisGet(data["ip"])

	if count > 0 {
		cmdb.GpuDisUpdateData(data, data["ip"])
	} else {
		cmdb.GpuAddData(data)
	}
}
